<template>
	<view>
		<!--  <view
      :class="'chat_title ' + (gotop ? 'main_title_hide' : 'main_title_show')"
    >
      <text>聊天</text>
    </view> -->

		<!-- <view class="chat_list_wraper" > -->
		<scroll-view scroll-y="true">
			<uni-notice-bar scrollable="true"  single="true" showClose="true" showIcon="true" :text="nowmsg">
			</uni-notice-bar>
			<view class="search" v-if="search_btn">
				<view @tap="openSearch">
					<icon type="search" size="12"></icon>
					<text>搜索</text>
				</view>
			</view>

			<view class="search_input" v-if="search_chats">
				<view>
					<icon type="search" size="12"></icon>
					<input placeholder="搜索" placeholder-style="color:#9B9B9B;line-height:21px;font-size:13px;" auto-focus confirm-type="search"
					 type="text" @confirm="onSearch" @input="onInput" :value="input_code" />
					<icon type="clear" size="12" @tap.stop="clearInput" v-if="show_clear"></icon>
				</view>
				<text @tap="cancel">取消</text>
			</view>
			<view class="list_box" @tap="gomsg" v-if="myname=='r123456'">
				<view class="list_left">
					<view class="list_pic">
						<image src='/static/logo.png' style="border-radius: 17%;"></image>
					</view>
					<view class="list_text">
						<view style="position: relative;top: 11px;">
							<text style="font-size: 18px;">充值消息</text><text style="font-size: 10px;background-color: #0873DE;padding: 3px;color: #FFFFFF;border-radius: 7px;position: relative;top: -5px;margin-left: 5px;">官方</text>
						</view>
						<!-- <text style="position: relative;top: 11px;" class="list_word">{{nowmsg[0].content}}</text> -->
					</view>
				</view>
			</view>
			<springBox ref="son"></springBox>
			
			<view class="listchat">
				<view v-for="(item, index) in arr" :key="index" class="chat_list"  @tap.stop="del_chat(item)" >
					<scroll-view scroll-y="true" >
						
						<swipe-delete>
							<view class="tap_mask" @tap.stop="into_chatRoom(item)" :data-item="item">
						
								<view class="list_box">
									<view class="list_left" :data-username="item.username">
										<view class="list_pic">
											<view class="em-msgNum" v-if="item.unReadCount > 0 || item.unReadCount == '99+'">{{ item.unReadCount }}</view>
						
											<image :src="
						      item.chatType == 'groupchat' ||
						      item.chatType == 'chatRoom'
						        ? item.headimg
						        : item.headimg
						    "
											 style="border-radius: 17%;"></image>
										</view>
										<view class="list_text">
											<text class="list_user">{{
						    item.chatType == "groupchat" ||
						    item.chatType == "chatRoom" ||
						    item.groupName
						      ? item.groupName
						      : item.nickname
						  }}</text>
											<text class="list_word" v-if="item.msg.data[0].data">{{
						    item.msg.data[0].data
						  }}</text>
											<text class="list_word" v-if="item.msg.type == 'img'">[图片]</text>
											<text class="list_word" v-if="item.msg.type == 'audio'">[语音]</text>
											<!-- <text class="list_word" v-if="item.msg.type == 'video'"
						    >[视频]</text
						  > -->
										</view>
									</view>
									<view class="list_right">
										<text :data-username="item.username">{{ item.time }}</text>
									</view>
								</view>
							</view>
						</swipe-delete>
					</scroll-view>
				</view>
			</view>

			<view v-if=" arr.length == 0&&myname!='r123456'" class="chat_noChat">当前没有历史聊天，添加一个好友开始聊天吧</view>
			<!-- </view> -->
		</scroll-view>
		<!-- bug: margin-bottom 不生效 需要加一个空标签-->
		<view style="height: 1px"></view>

		<view class="mask" @tap="close_mask" v-if="show_mask"></view>

		<view :class="isIPX ? 'chatRoom_tab_X' : 'chatRoom_tab'">
			<view class="tableBar">
				<view v-if="unReadSpotNum > 0 || unReadSpotNum == '99+'" :class="
				'em-unread-spot ' + (unReadSpotNum == '99+' ? 'em-unread-spot-litleFont' : '')
				">{{ unReadSpotNum }}</view>
				<image :class="unReadSpotNum > 0 || unReadSpotNum == '99+' ? 'haveSpot' : ''" src="/static/bottom/xiaoxired.png"></image>
				<text class="activeText" style="font-size: 13px;">聊天</text>
			</view>

			<view class="tableBar" @tap="tab_contacts">
				<view v-if="unReadTotalNotNum > 0" class="em-unread-spot">{{ unReadTotalNotNum }}</view>
				<image :class="unReadTotalNotNum > 0 ? 'haveSpot': ''" src="/static/bottom/tongxunlu.png"></image>
				<text style="font-size: 13px;">通讯录</text>
			</view>

			<!-- <view class="tableBar" @tap="tab_notification">
				<image :class="unReadTotalNotNum > 0 ? 'haveSpot' : ''" src="/static/bottom/faxian.png"></image>
				<text style="font-size: 13px;">发现</text>
			</view> -->

			<view class="tableBar" @tap="tab_setting">
				<image src="/static/bottom/my.png"></image>
				<text style="font-size: 13px;">我的</text>
			</view>
		</view>
	</view>
</template>

<script>
	import uniNoticeBar from '@/components/uni-notice-bar/uni-notice-bar.vue'
	let disp = require("../../utils/broadcast");
	var WebIM = require("../../utils/WebIM")["default"];
	let isfirstTime = true;
	import swipeDelete from "../../comps/swipedelete/swipedelete";
	import springBox from "../../components/springBox/springBox";
	import uniSwipeAction from "../../components/uni-swipe-action/uni-swipe-action.vue"
	export default {
		data() {
			return {
				options: [
					{
					text: '置顶'
				}, {
					text: '标记为已读',
					style: {
						backgroundColor: 'rgb(254,156,1)'
					}
				},
				{
					text: '删除',
					style: {
						backgroundColor: 'rgb(255,58,49)'
					}
				}],
				nowmsg:"",
				search_btn: true,
				search_chats: false,
				show_mask: false,
				yourname: "",
				unReadSpotNum: 0,
				unReadNoticeNum: 0,
				messageNum: 0,
				unReadTotalNotNum: 0,
				arr: [],
				show_clear: false,
				member: "",
				isIPX: false,
				gotop: false,
				input_code: "",
				myname:'',
				clickshow:true 
			};
		},

		components: {
			swipeDelete,
			springBox,
			uniSwipeAction
		},
		onNavigationBarButtonTap(e) {
			if (e.float == 'right') {
				this.$refs.son.HiddenClick();
			}
		},
		props: {},
		watch: {
			arr(e) {
				for (let i = 0; i < this.arr.length; i++) {
					if (this.arr[i].chatType == "singleChat" || this.arr[i].chatType == "chat") {
						let token = uni.getStorageSync('token')
						uni.request({
							url: this.G_base + '/api/lz/ltzh',
							method: 'POST',
							header: {
								'content-type': 'application/x-www-form-urlencoded',
								'Authori-zation': 'Bearer ' + token
							},
							data: {
								list: this.arr[i].username,
								status: 1
							},
							processData: true,
							success: res => {
								this.arr[i].headimg = res.data.data.useravatar
								this.arr[i].nickname = res.data.data.nickname
							}
						})
					} else {
						let token = uni.getStorageSync('token')
						uni.request({
							url: this.G_base + '/api/lz/ltzh',
							method: 'POST',
							header: {
								'content-type': 'application/x-www-form-urlencoded',
								'Authori-zation': 'Bearer ' + token
							},
							data: {
								list: this.arr[i].groupName,
								status: 2
							},
							processData: true,
							success: res => {
								this.arr[i].headimg = res.data.data.useravatar
								this.arr[i].nickname = res.data.data.nickname
							}
						})
					}

				}
			}
		},
		onLoad() {
			let me = this;
			//监听加好友申请
			disp.on("em.subscribe", function() {
				me.setData({
					messageNum: getApp().globalData.saveFriendList.length,
					unReadTotalNotNum: getApp().globalData.saveFriendList.length + getApp().globalData.saveGroupInvitedList.length
				});
			});

			//监听解散群
			disp.on("em.invite.deleteGroup", function() {
				me.listGroups();
				me.getRoster();
				// me.getChatList()
				me.setData({
					arr: me.getChatList(),
					messageNum: getApp().globalData.saveFriendList.length
				});
			});

			//监听未读消息数
			disp.on("em.unreadspot", function(message) {
				// me.getChatList()
				me.setData({
					arr: me.getChatList(),
					unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum
				});
			}); //监听未读加群“通知”

			disp.on("em.invite.joingroup", function() {
				me.setData({
					unReadNoticeNum: getApp().globalData.saveGroupInvitedList.length,
					unReadTotalNotNum: getApp().globalData.saveFriendList.length + getApp().globalData.saveGroupInvitedList.length
				});
			});
			disp.on("em.contacts.remove", function() {
				me.getRoster(); // me.setData({
				// 	arr: me.getChatList(),
				// 	unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum,
				// });
			});
			this.getRoster();
		},

		onShow: function() {
			uni.request({
				url: this.G_base + '/api/lz/xtxxOne',
				method: 'GET',
				header: {
					'content-type': 'application/x-www-form-urlencoded',
				},
				success: res => {
					if (res.data.status == 200) {
						this.nowmsg="["+res.data.data.title+"] " + res.data.data.content
					}
				}
			})
			this.myname = uni.getStorageSync('name')
			// uni.request({
			// 	url: this.G_base + '/api/lz/xtxx',
			// 	method: 'GET',
			// 	header: {
			// 		'content-type': 'application/x-www-form-urlencoded',
			// 	},
			// 	success: res => {
			// 		if (res.data.status == 200) {
			// 			this.nowmsg=res.data.data
			// 		}
			// 	}
			// })
			for (let i = 0; i < this.arr.length; i++) {
				if (this.arr[i].chatType == "singleChat" || this.arr[i].chatType == "chat") {
					let token = uni.getStorageSync('token')
					uni.request({
						url: this.G_base + '/api/lz/ltzh',
						method: 'POST',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authori-zation': 'Bearer ' + token
						},
						data: {
							list: this.arr[i].username,
							status: 1
						},
						processData: true,
						success: res => {
							this.arr[i].headimg = res.data.data.useravatar
							this.arr[i].nickname = res.data.data.nickname
						}
					})
				} else {
					let token = uni.getStorageSync('token')
					uni.request({
						url: this.G_base + '/api/lz/ltzh',
						method: 'POST',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authori-zation': 'Bearer ' + token
						},
						data: {
							list: this.arr[i].groupName,
							status: 2
						},
						processData: true,
						success: res => {
							this.arr[i].headimg = res.data.data.useravatar
							this.arr[i].nickname = res.data.data.nickname
						}
					})
				}

			}
			this.setData({
				arr: this.getChatList(),
				unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum,
				messageNum: getApp().globalData.saveFriendList.length,
				unReadNoticeNum: getApp().globalData.saveGroupInvitedList.length,
				unReadTotalNotNum: getApp().globalData.saveFriendList.length + getApp().globalData.saveGroupInvitedList.length
			});

			if (getApp().globalData.isIPX) {
				this.setData({
					isIPX: true
				});
			}
		},
		methods: {
			action_click(e, item) {
				switch (e.index) {
					case 2:
						this.del_chat(item);
						break;
					default:
						break;
				}
			},
			listGroups() {
				var me = this;
				return WebIM.conn.getGroup({
					limit: 50,
					success: function(res) {
						uni.setStorage({
							key: "listGroup",
							data: res.data
						});
						me.getChatList();
					},
					error: function(err) {
						console.log(err);
					}
				});
			},

			getRoster() {
				let me = this;
				let rosters = {
					success(roster) {
						var member = [];

						for (let i = 0; i < roster.length; i++) {
							if (roster[i].subscription == "both") {
								member.push(roster[i]);
							}
						}

						uni.setStorage({
							key: "member",
							data: member
						});
						me.setData({
							member: member
						});
						me.listGroups(); //if(!systemReady){

						disp.fire("em.main.ready"); //systemReady = true;
						//}
						// me.getChatList()
						me.setData({
							arr: me.getChatList(),
							unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum
						});
					},

					error(err) {
						console.log(err);
					}

				};
				WebIM.conn.getRoster(rosters);
			},

			// 不包含陌生人版本
			getChatList() {
				var array = [];
				var member = uni.getStorageSync("member");
				var myName = uni.getStorageSync("myUsername");
				var listGroups = uni.getStorageSync('listGroup') || [];

				for (let i = 0; i < member.length; i++) {
					let newChatMsgs = uni.getStorageSync(member[i].name + myName) || [];
					let historyChatMsgs = uni.getStorageSync("rendered_" + member[i].name + myName) || [];
					let curChatMsgs = historyChatMsgs.concat(newChatMsgs);

					if (curChatMsgs.length) {
						let lastChatMsg = curChatMsgs[curChatMsgs.length - 1];
						lastChatMsg.unReadCount = newChatMsgs.length;

						if (lastChatMsg.unReadCount > 99) {
							lastChatMsg.unReadCount = "99+";
						}

						let dateArr = lastChatMsg.time.split(' ')[0].split('-');
						let timeArr = lastChatMsg.time.split(' ')[1].split(':');
						let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2];
						lastChatMsg.dateTimeNum = `${timeArr[1]}${timeArr[2]}`;
						lastChatMsg.time = `${timeArr[0]}时${timeArr[1]}分`;
						array.push(lastChatMsg);
					}
				}

				for (let i = 0; i < listGroups.length; i++) {
					let newChatMsgs = uni.getStorageSync(listGroups[i].groupid + myName) || [];
					let historyChatMsgs = uni.getStorageSync("rendered_" + listGroups[i].groupid + myName) || [];
					let curChatMsgs = historyChatMsgs.concat(newChatMsgs);
					if (curChatMsgs.length) {
						let lastChatMsg = curChatMsgs[curChatMsgs.length - 1];
						lastChatMsg.unReadCount = newChatMsgs.length;
						if (lastChatMsg.unReadCount > 99) {
							lastChatMsg.unReadCount = "99+";
						}
						let dateArr = lastChatMsg.time.split(' ')[0].split('-')
						let timeArr = lastChatMsg.time.split(' ')[1].split(':')
						let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2]
						lastChatMsg.time = ` ${timeArr[0]}时${timeArr[1]}分`
						lastChatMsg.dateTimeNum = `${timeArr[1]}${timeArr[2]}`
						lastChatMsg.groupName = listGroups[i].groupname
						array.push(lastChatMsg);
					}
				}

				array.sort((a, b) => {
					return b.dateTimeNum - a.dateTimeNum;
				});
				return array;
			},


			//// 包含陌生人版本
			// getChatList(){
			// 	var myName = uni.getStorageSync("myUsername");
			// 	var array = [];
			// 	const me = this
			// 	uni.getStorageInfo({
			// 		success: function(res){
			//       let storageKeys = res.keys
			// 			let newChatMsgKeys = [];
			// 			let historyChatMsgKeys = [];
			// 			storageKeys.forEach((item) => {
			// 				if (item.indexOf(myName) > -1 && item.indexOf('rendered_') == -1) {
			// 					newChatMsgKeys.push(item)
			// 				}else if(item.indexOf(myName) > -1 && item.indexOf('rendered_') > -1){
			// 					historyChatMsgKeys.push(item)
			// 				}
			// 			})

			// 		  cul.call(me, newChatMsgKeys, historyChatMsgKeys)
			// 		}
			// 	})

			// 	function cul(newChatMsgKeys, historyChatMsgKeys){
			// 		let array = []
			// 		let lastChatMsg;
			// 		for(let i = 0; i < historyChatMsgKeys.length; i++){
			// 			let index = newChatMsgKeys.indexOf(historyChatMsgKeys[i].slice(9))
			// 			if ( index > -1 ) {
			//         let newChatMsgs = uni.getStorageSync(newChatMsgKeys[index]) || [];
			// 				if(newChatMsgs.length){
			// 					lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
			// 					lastChatMsg.unReadCount = newChatMsgs.length;
			// 					if(lastChatMsg.unReadCount > 99) {
			// 						lastChatMsg.unReadCount = "99+";
			// 					}
			// 					let dateArr = lastChatMsg.time.split(' ')[0].split('-')
			// 					let timeArr = lastChatMsg.time.split(' ')[1].split(':')
			// 					let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2]
			// 					lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`
			// 					lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}时${timeArr[1]}分`
			// 					newChatMsgKeys.splice(index, 1)
			// 				}else{
			// 					let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
			// 					if (historyChatMsgs.length) {
			// 						lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
			// 						let dateArr = lastChatMsg.time.split(' ')[0].split('-')
			// 						let timeArr = lastChatMsg.time.split(' ')[1].split(':')
			// 						let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2]
			// 						lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`
			// 						lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}时${timeArr[1]}分`
			// 					}
			// 				}
			// 			}else{
			// 				let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
			// 				if (historyChatMsgs.length) {
			// 					lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
			// 					let dateArr = lastChatMsg.time.split(' ')[0].split('-')
			// 					let timeArr = lastChatMsg.time.split(' ')[1].split(':')
			// 					let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2]
			// 					lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`
			// 					lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}时${timeArr[1]}分`
			// 				}

			// 			}
			// 			lastChatMsg && array.push(lastChatMsg)
			// 		}

			// 		for(let i = 0; i < newChatMsgKeys.length; i++){
			// 			let newChatMsgs = uni.getStorageSync(newChatMsgKeys[i]) || [];
			// 			if(newChatMsgs.length){
			// 				lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
			// 				lastChatMsg.unReadCount = newChatMsgs.length;
			// 				if(lastChatMsg.unReadCount > 99) {
			// 					lastChatMsg.unReadCount = "99+";
			// 				}
			// 				let dateArr = lastChatMsg.time.split(' ')[0].split('-')
			// 				let timeArr = lastChatMsg.time.split(' ')[1].split(':')
			// 				let month = dateArr[2] < 10 ? '0' + dateArr[2] : dateArr[2]
			// 				lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`
			// 				lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}时${timeArr[1]}分`
			// 				array.push(lastChatMsg)
			// 			}
			// 		}

			// 		array.sort((a, b) => {
			// 			return b.dateTimeNum - a.dateTimeNum
			// 		})
			// 		this.setData({
			// 			arr: array
			// 		})
			// 	}
			// },

			//获取头像
			openSearch: function() {
				this.setData({
					search_btn: false,
					search_chats: true,
					gotop: true
				});
			},
			onSearch: function(val) {
				// this.getChatList()
				let searchValue = val.detail.value;
				let chartList = this.getChatList();
				let serchList = [];
				chartList.forEach((item, index) => {
					if (String(item.username).indexOf(searchValue) != -1) {
						serchList.push(item);
					}
				});
				this.setData({
					arr: serchList
				});
			},
			//消息
			gomsg(){
				uni.navigateTo({
					url:'/pages/msglist/Moneylist'
				})
			},
			cancel: function() {
				// this.getChatList()
				this.setData({
					search_btn: true,
					search_chats: false,
					arr: this.getChatList(),
					unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum,
					gotop: false
				});
			},
			clearInput: function() {
				this.setData({
					input_code: '',
					show_clear: false
				});
			},
			onInput: function(e) {
				let inputValue = e.detail.value;

				if (inputValue) {
					this.setData({
						show_clear: true
					});
				} else {
					this.setData({
						show_clear: false
					});
				}
			},
			tab_contacts: function() {
				let that=this;
				if(that.clickshow) {
					that.clickshow = false;
					uni.redirectTo({
						url: "../main/main?myName=" + uni.getStorageSync("myUsername")
					});
					setTimeout(function () {
						that.clickshow = true;
					}, 1500)
				} else {
					//如果一直走else分支可能是你没有在页面的data下面挂载clickshow:true,不然一直都会走else
					console.log("请勿频繁点击")
				}
			},
			close_mask: function() {
				this.setData({
					search_btn: true,
					search_chats: false,
					show_mask: false
				});
			},
			tab_setting: function() {
				let that=this;
				if(that.clickshow) {
					that.clickshow = false;
					uni.redirectTo({
						url: "../setting/setting"
					});
					setTimeout(function () {
						that.clickshow = true;
					}, 1500)
				} else {
					//如果一直走else分支可能是你没有在页面的data下面挂载clickshow:true,不然一直都会走else
					console.log("请勿频繁点击")
				}
			},
			tab_notification: function() {
				uni.redirectTo({
					url: "../faxian/newfaxian"
				});
			},
			into_chatRoom: function(event) {
				let detail = event; //群聊的chatType居然是singlechat？脏数据？ 等sdk重写后整理一下字段

				if (detail.chatType == 'groupchat' || detail.chatType == 'chatRoom' || detail.groupName) {
					this.into_groupChatRoom(detail);
				} else {
					this.into_singleChatRoom(detail);
				}
			},
			//	单聊
			into_singleChatRoom: function(detail) {
				var my = uni.getStorageSync("myUsername");
				var nameList = {
					myName: my,
					your: detail.username
				};
				uni.navigateTo({
					url: "../chatroom/chatroom?username=" + JSON.stringify(nameList)+'&nickname='+detail.nickname
				});
			},
			//	群聊 和 聊天室 （两个概念）
			into_groupChatRoom: function(detail) {
				let token = uni.getStorageSync('token')
				uni.request({
					url: this.G_base + '/api/lz/hqqid',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + token
					},
					data: {
						name: detail.groupName
					},
					success: res => {
						if (res.data.status == 200) {
							console.log(res)
							var my = uni.getStorageSync("myUsername");
							var nameList = {
								myName: my,
								your: detail.groupName,
								groupId: detail.info.to,
								qid: res.data.data.id
							};
							uni.navigateTo({
								url: "../groupChatRoom/groupChatRoom?username=" + JSON.stringify(nameList)
							});
						}
					}
				})
				// var my = uni.getStorageSync("myUsername");
				// var nameList = {
				//   myName: my,
				//   your: detail.groupName,
				//   groupId: detail.info.to
				// };
				// uni.navigateTo({
				//   url: "../groupChatRoom/groupChatRoom?username=" + JSON.stringify(nameList)
				// });
			},
			gomap: function() {
				uni.navigateTo({
					url: '/pages/test/map'
				})
			},
			del_chat: function(event) {
				console.log(1)
				console.log(event)
				++event.listnum
				let me = this
				let detail = event;
				let nameList;

				if (detail.chatType == 'groupchat' || detail.chatType == 'chatRoom') {
					nameList = {
						your: detail.info.to
					};
				} else {
					nameList = {
						your: detail.username
					};
				}

				var myName = uni.getStorageSync("myUsername");
				// var currentPage = getCurrentPages();
				// console.log('currentPage>>',currentPage);
				uni.showModal({
					title: "删除该聊天记录",
					confirmText: "删除",
					success: function(res) {
						if (res.confirm) {
							console.log(nameList.your)
							console.log(myName)
							uni.setStorageSync(nameList.your + myName, "");
							uni.setStorageSync("rendered_" + nameList.your + myName, "");

							// if (currentPage[0]) {
							//   console.log('currentPage[0]>>',currentPage[0]);
							//   const val = currentPage[0]
							//   val.onShow();
							// }
							me.getChatList()

							disp.fire("em.chat.session.remove");
						}
					},
					fail: function(err) {}
				});
			}
		}
	};
</script>
<style>
	@import "./chat.css";
</style>
